#ifndef IO_SERVICE_POOL_HPP
#define IO_SERVICE_POOL_HPP

#include <boost/asio.hpp>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>

class io_service_pool 
{
public:
    io_service_pool();
    ~io_service_pool();

    void init(std::size_t pool_size);
    void wait_for_stop();
	boost::shared_ptr<boost::asio::io_service> get_io_service();

private:
    io_service_pool(const io_service_pool&);
    const io_service_pool& operator=(const io_service_pool&);

private:
	typedef boost::shared_ptr<boost::asio::io_service> io_service_ptr;
	typedef boost::shared_ptr<boost::asio::io_service::work> work_ptr;

    std::vector<io_service_ptr> m_io_services;
    std::vector<work_ptr>       m_works;

    uint32_t					m_next_io_service;
    std::size_t                 m_pool_size;
    std::vector<boost::shared_ptr<boost::thread> > m_io_threads;
};

#endif // HTTP_SERVER2_IO_SERVICE_POOL_HPP
